package com.jama.carouselviewexample.slice;

import com.jama.carouselview.views.BaseCarouselView;
import com.jama.carouselview.views.CarouselView;
import com.jama.carouselviewexample.ResourceTable;
import com.jama.carouselviewexample.adapter.StartListProvider;
import com.jama.carouselviewexample.adapter.StartTallListProvider;
import com.jama.carouselviewexample.bean.MovieBean;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * StartCarouselActivitySlice
 *
 * @since 2021-05-20
 */
public class StartCarouselSlice extends AbilitySlice {
    private Text moveText;
    private Text trendText;
    private List<MovieBean> movieBeans;
    private List<MovieBean> bigMovieBeans;
    private CarouselView bigList;
    private BaseCarouselView listContainer;
    private StartListProvider listProvider;
    private StartTallListProvider tallListProvider;

    /**
     * onStart
     *
     * @param intent intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_start_carousel_activity);
        initView();
    }

    private void initView() {
        moveText = (Text) findComponentById(ResourceTable.Id_textView5);
        trendText = (Text) findComponentById(ResourceTable.Id_textView6);
        bigList = (CarouselView) findComponentById(ResourceTable.Id_base_list);
        listContainer = (BaseCarouselView) findComponentById(ResourceTable.Id_list_container_start_num);
        moveText.setFont(Font.DEFAULT_BOLD);
        trendText.setFont(Font.DEFAULT_BOLD);
        movieBeans = createListBean();
        bigMovieBeans = createBigListBean();
        listProvider = new StartListProvider(movieBeans, this);
        listContainer.setItemProvider(listProvider);
        listContainer.setOrientation(Component.HORIZONTAL);

        tallListProvider = new StartTallListProvider(bigMovieBeans, this);
        bigList.setItemProvider(tallListProvider);
        bigList.setOrientation(Component.HORIZONTAL);

        bigList.toChangeViewBig(0);
        bigList.postLayout();
        bigList.setReboundEffect(true);
        listContainer.setLongClickable(false);
        int firstVisibleItemPosition = bigList.getFirstVisibleItemPosition();
        bigList.toChangeViewBig(firstVisibleItemPosition);
        bigList.postLayout();
        tallListProvider.notifyDataChanged();

    }


    private List<MovieBean> createBigListBean() {
        List<MovieBean> list = new ArrayList<>();
        list.add(new MovieBean(ResourceTable.Media_harry_potter, "Harry Potter ", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_konosuba, "Konosuba", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_i_am_legend, "I Am Legend", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_priates, "Pirates of the Caribbean", ResourceTable.Media_smart));
        return list;
    }

    private List<MovieBean> createListBean() {
        List<MovieBean> list = new ArrayList<>();
        list.add(new MovieBean(ResourceTable.Media_lord_of_ring, "Lord of the Rings", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_naruto, "The  Last  Naruto  the  Movie", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_spirited, "Spirited Away", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_mad_max, "Mad Max", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_harry_potter, "Harry Potter ", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_konosuba, "Konosuba", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_i_am_legend, "I Am Legend", ResourceTable.Media_smart));
        list.add(new MovieBean(ResourceTable.Media_priates, "Pirates of the Caribbean", ResourceTable.Media_smart));
        return list;
    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     * onForeground
     *
     * @param intent intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
